package cn.web.web_module.controller;

import cn.itcast.util.ResponseEntity;
import cn.web.web_module.service.RechargeService;
import cn.wx.MerchantMyConfig;
import cn.wx.MyConfig;
import io.netty.handler.codec.http.HttpRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author: 张松
 * @Description:
 * @Date: Created in 10:08 2021/2/25
 * @Modified By:
 */

@RestController
@RequestMapping(value = "/Recharge",produces="application/json;charset=UTF-8")
public class RechargesController {

    @Resource
    private RechargeService rechargeService;

    @PostMapping("HorsemanRecharge")
    public ResponseEntity HorsemanRecharge(@RequestBody Map<String,String> userRechargeInfo){
        ResponseEntity responseEntity = null;
        try {
            responseEntity = rechargeService.horsemanRechargeService(userRechargeInfo,new MyConfig());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return responseEntity;
    }

    @PostMapping("MerchantRecharge")
    public ResponseEntity MerchantRecharge(@RequestBody Map<String,String> userRechargeInfo){
        ResponseEntity responseEntity = null;
        try {
            responseEntity = rechargeService.horsemanRechargeService(userRechargeInfo,new MerchantMyConfig());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return responseEntity;
    }



    @PostMapping("RechargeNotifyUrl")
    public ResponseEntity RechargeNotifyUrl(HttpServletRequest httpServletRequest){
        ResponseEntity responseEntity = rechargeService.RechargeNotifyUrl(httpServletRequest);
        return responseEntity;
    }

    @PostMapping("deleteRedisHorsemanPay")
    public ResponseEntity deleteRedisHorsemanPay(@RequestBody Map<String,String> horsemanOpenid){
        boolean ifDelete=rechargeService.deleteRedisHorsemanPay(horsemanOpenid);
        if (ifDelete){
            return new ResponseEntity(200,"删除成功");
        }
        return new ResponseEntity(300,"删除失败");

    }

}
